package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.SystemDictionaryItemQueryObject;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/dictionaryItem")
public class SystemDictionaryItemController {
	
	@Autowired
	private ISystemDictionaryItemService dictionaryItemService;



	@Autowired
	private ISystemDictionaryService dictionaryService;

	@RequestMapping("list")
	public String list(Model model, @ModelAttribute("qo")SystemDictionaryItemQueryObject qo){
		//int i=1/0;
		model.addAttribute("result", dictionaryItemService.query(qo));
		model.addAttribute("dictionarys", dictionaryService.selectAll());
		return "/dictionaryItem/list";
	}


	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Object saveOrUpdate(SystemDictionaryItem entity){
		JSONResult result = new JSONResult();
		try {
			//int i = 1/0;
			if(entity.getId() != null){
                dictionaryItemService.updateByPrimaryKey(entity);
            }else{
                dictionaryItemService.insert(entity);
            }
		} catch (Exception e) {
			e.printStackTrace();
			result.mark(e.getMessage());
		}

		return result;
	}
	
}
